package com.roger.myHome.controller;

import com.roger.myHome.entity.qto.RefreshToken;
import com.roger.myHome.service.TokenService;
import com.roger.myHome.util.DateUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
@RequestMapping("/token")
public class TokenController {

    @Resource
    private TokenService tokenService;

    @PostMapping(value = "/refresh")
    public String refresh (HttpServletRequest request){
        String now = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
        System.err.println(now + ":刷新token");
        RefreshToken refreshToken = new RefreshToken();
        refreshToken.setRefreshToken(request.getParameter("refreshToken"));
        refreshToken.setExpireTime(request.getParameter("expireTime"));

        return tokenService.refresh(refreshToken);
    }
}
